Forums de discussion

Model-context tags and checkbox inputs

thumbnail
Chris Maggiulli, modifié il y a 6 années.

Model-context tags and checkbox inputs

New Member Publications: 19 Date d'inscription: 15/12/16 Publications récentes
I am using the model-context tag to populate a form on a jsp based on POJO I have stored in the response from a class that extends MVC Portlet. Here is the POJO


public class SiteMemberSearchContainerRow {
    private String screenName;
    private Long userId; 
    private Boolean administrator;
    private Boolean active;
    private String key;
    private Date createdDate;
    
    public SiteMemberSearchContainerRow(String screenName, Long userId, Boolean administrator, Boolean active, String key, Date createdDate) {
	this.screenName = screenName;
	this.userId = userId;
	this.administrator = administrator;
	this.active = active;
	this.key = key;
	this.createdDate = createdDate;
    }
    
    
    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getScreenName() {
        return screenName;
    }
    public void setScreenName(String screenName) {
        this.screenName = screenName;
    }
    public Long getUserId() {
        return userId;
    }
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    public Boolean getAdministrator() {
        return administrator;
    }
    public void setAdministrator(Boolean administrator) {
        this.administrator = administrator;
    }
    public Boolean getActive() {
        return active;
    }
    public void setActive(Boolean active) {
        this.active = active;
    }
    public String getKey() {
        return key;
    }
    public void setKey(String key) {
        this.key = key;
    }
}


My JSP code


<aui:model-context bean="${siteMember}" model="<%= SiteMemberSearchContainerRow.class %>" />

<aui:form action="<%= editSoftwareKeyActionURL %>" method="post" name="fm">
		<aui:field-wrapper>
			<aui:input label="label.user.id" name="userId" id="userId" type="text" readonly="true" />	
			<aui:input label="label.user.name" name="screenName" id="screenName" type="text" readonly="true" />
			<aui:input label="label.created.date" name="createdDate" id="createdDate" type="text" readonly="true" />	
			<aui:input label="label.software.key" name="key" id="key" type="text">
				<aui:validator name="required"></aui:validator>
				<aui:validator name="maxLength">5</aui:validator>
				<aui:validator name="minLength">5</aui:validator>
			</aui:input>
			<aui:input label="label.administrator" name="administrator" id="administrator" type="checkbox" />			
			<aui:input label="label.active" name="active" id="active" type="checkbox" />			
			<aui:button-row>
				<aui:button type="submit" />
			</aui:button-row>
		</aui:field-wrapper>
</aui:form>


It fills out all the appropriate text inputs but will not check/uncheck any checkbox inputs. Any thoughts?
thumbnail
Nate Cavanaugh, modifié il y a 6 années.

RE: Model-context tags and checkbox inputs (Réponse)

Junior Member Publications: 94 Date d'inscription: 27/11/06 Publications récentes
Hi Chris,
The only thing you need to do is to change your checkboxes to the following:
<aui:input label="label.administrator" name="administrator" />            
            <aui:input label="label.active" name="active" />


(and you might be able to remove the labels as well, if you don't mind them using their formatted name, e.g. the administrator field will have an Administrator label).

The reason it wasn't working was because when you set the model context, we assume you want the types of the fields to be inferred from it's type in the model.

When you explicitly set a type, you would also have to set the value.

Also, you really only need the name attribute on the aui:inputs, as it will automatically add the appropriate ID as well (unless you need them to be separate, then it can be handy to set them both).

HTH emoticon
thumbnail
Chris Maggiulli, modifié il y a 6 années.

RE: Model-context tags and checkbox inputs

New Member Publications: 19 Date d'inscription: 15/12/16 Publications récentes
Great! I really appreciate you giving me the example code with an explanation as well. I also greatly appreciate the bit about supplying only the name as it will automatically add the id attribute too.