Announcement Announcement Module
Collapse
No announcement yet.
Help With Select and Property Editor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help With Select and Property Editor

    Can anyone tell me why the Select box in the following never has the correct option selected. The correct value is being set when the for is submitted but when you navigate back to the page the default is always shown.

    Code:
    public class CustomRiskCategoryEditor extends PropertyEditorSupport
    {
    	private static final Logger logger = Logger.getLogger(CustomRiskCategoryEditor.class);
    	
    	List<RiskCategory> riskCats;
    	RiskCategory selected;
    	
    	public CustomRiskCategoryEditor(List<RiskCategory> riskCats, RiskCategory selected)
    	{
    		this.riskCats = riskCats;
    		this.selected = selected;
    		
    		/*for(RiskCategory cat : riskCats)
    		{
    			if(cat.getId() == selected.getId())
    			{
    				selected = cat;
    				break;
    			}
    		}*/
    	}
    	
    	public void setAsText(String text)
    	{
    		if(! text.equals(""))
    		{
    			int riskSequence = Integer.parseInt(text);
    			
    			for(RiskCategory cat : riskCats)
    			{
    				if(cat.getId() == riskSequence)
    				{
    					setValue(cat);
    					
    					if(logger.isDebugEnabled())
    					{
    						logger.debug("Setting Risk Category :: " + cat.getName());
    					}
    					
    					break;
    				}
    			}
    		}
    	}
    
    	public String getAsText()
    	{
    		String riskCatId = ""; 
    		
    		RiskCategory cat = (RiskCategory)getValue();
    		
    		if(cat != null)
    		{
    			return Integer.toString(cat.getId());
    		}
    		
    		if(logger.isDebugEnabled())
    		{
    			logger.debug("Returning Risk Sequence :: " + riskCatId);
    		}
    		
    		return riskCatId;
    	}
    	
    /*	public void setValue(Object value)
    	{
    		selected = (RiskCategory)value;
    	}*/
    	
    	public Object getValue()
    	{
    		return selected;
    	}
    }
    Code:
    <form:select path="objectiveCommandBean.riskCategory">
       <form:option value="" label="No goal specific risk category"/>
       <form:options items="${allRiskCategories}" itemLabel="name" itemValue="id"/>
    </form:select>
Working...
X