JSF input for multiple bean property support

I have some cases where I have a JSF page and for a single login I would like to set more than one value based on the bean without doing the code in the bean fallback.

I can set one value:

 <h:selectOneRadio id="selectMembershipLevel" class="TODO_SELECT" 
value="#{joinBackingBean.map[joinBackingBean.map.primary_memberInfo_membershipType_code]}">
 <f:selectItem id="basic" itemLabel="#{overrideMsg.pbBasic}" itemValue="B" />
 <f:selectItem id="plus" itemLabel="#{overrideMsg.pbPlus}" itemValue="P" />
 <f:selectItem id="plusRV" itemLabel="#{overrideMsg.pbPlusRV}" itemValue="RV" />

      

But if I wanted to install more than one at once, can this be done in the JSF page?

#{joinBackingBean.map[joinBackingBean.map.primary_memberInfo_membershipType_code]}
#{joinBackingBean.map[joinBackingBean.map.primary_memberInfo_membershipType_desc]}//Bdesc
#{joinBackingBean.map[joinBackingBean.map.primary_memberInfo_membershipType_type]}//Btype

      

+3


source to share


1 answer


Bind other properties with <h:inputHidden>

and use JavaScript during the change

first input event to control the value of these hidden inputs with the same value as the first input current value.

Here's a start example:



<h:form id="form">
    <h:selectOneRadio value="#{bean.input1}" onchange="document.getElementById('form:input2').value = document.getElementById('form:input3').value = this.value">
        <f:selectItem itemValue="one" />
        <f:selectItem itemValue="two" />
        <f:selectItem itemValue="three" />
    </h:selectOneRadio>
    <h:inputHidden id="input2" value="#{bean.input2}" />
    <h:inputHidden id="input3" value="#{bean.input3}" />
    ...
</h:form>

      

Obviously feel free to refactor your JS function or throw in some kind of jQuery. Keep in mind that none of this will work if the client is JS disabled and that the end user can manipulate the JS code and request parameters. A server side solution is more reliable when you absolutely need equal values.

+5


source







All Articles