I am using JBoss 5.01 and richfaces: 3.3. When the first h:selectOneMenu id="codOrgao" changes, I need to get the year value of the second h:selectOneMenu id="ano" and then load the third h:selectOneMenu id="codMembro". That is the code that I wrote, I don't know the reason, but doesn't work.
a4j supporte doesn't work(in valueChangeListener="#{populaMembros.pegaListaMembros} class I wrote a simple System.out.println("listener called")" to see if that method is called but it isn't ). Thanks in advance for any help!!!
<h:form styleClass="labelPorCima">
<h:panelGrid id="mpanel">
<div class="content field">
<label for="codOrgao">Selecione um orgão</label>
<h:selectOneMenu id="codOrgao" styleClass="textoLongo" valueChangeListener="#{populaMembros.pegaListaMembros}">
<f:selectItems value="#{populaOrgaosBean.listaItensOrgaos}" />
<a4j:support event="onchange" reRender="codMembro"/>
</h:selectOneMenu>
</div>
<h:selectOneMenu id="ano" styleClass="inputNome">
<f:selectItem itemLabel="2012"/>
<f:selectItem itemLabel="2011"/>
<f:selectItem itemLabel="2010"/>
<f:selectItem itemLabel="2009"/>
<f:selectItem itemLabel="2008"/>
</h:selectOneMenu>
<div class="content field ">
<label for="membro" class="membro">Nome do Membro</label>
<h:selectOneMenu id="codMembro" styleClass="inputNome" disabled="true">
<f:selectItem itemLabel="Selecione um membro" />
</h:selectOneMenu>
</div>
</h:panelGrid>
</h:form>
codOrgao won't fire it's value change listener because it doesn't have a value attribute. The component needs to have a value attribute, bound to a backing bean variable
You should move the actionListener from the <h:selectOneMenu/> to the <a4j:support/>.
So in all, your code should look like:
<h:selectOneMenu id="codOrgao" value="#{bean.theValue}" styleClass="textoLongo">
<f:selectItems value="#{populaOrgaosBean.listaItensOrgaos}" />
<a4j:support event="onchange" reRender="codMembro" actionListener="#{populaMembros.pegaListaMembros}"/>
</h:selectOneMenu>
Related
I have a form with JSF 1.2 & RichFaces 3.3.4.
Currently I'm able to use AJAX for update value. When I update the form (by clicking element value1) I properly update element value2, but the value1, that updates the form, is submitted.
I would like to update the element value2 of the form without submitting the element value1.
It is possible?
<h:form id="formId">
<h:selectOneMenu id="value1" value="#{searchCriteria.value1}">
<f:selectItem itemLabel="---" itemValue="#{null}" />
<f:selectItem itemLabel="a" itemValue="a" />
<f:selectItem itemLabel="b" itemValue="b" />
<a4j:support event="onchange" action="#{searchCriteria.changeAction}"
reRender="value2" />
</h:selectOneMenu>
<h:selectOneMenu id="value2" value="#{searchCriteria.value2}">
<f:selectItems value="#{searchCriteria.valueList}" />
</h:selectOneMenu>
<a4j:commandButton action="#{searchCriteria.search}" value="Search"
reRender="formId" />
</h:form>
I'm having a trouble with getting rid of required message.
I have a form in which I have a few fields and a button.
When I press a button there is validation that checks if required fields where filled with values if not then required message is displayed for invalid value/component.
Now I want to select a value from selectOneMenu or type something into inputText and when I do that I want the required message to dissapear without need to press the button again.
How would you do that?
I've tried to remove message with sth like this, but it doesn't seems to work:
Iterator<FacesMessage> msgIterator = FacesContext.getCurrentInstance().getMessages();
while (msgIterator.hasNext())
{
FacesMessage facesMessage = msgIterator.next();
msgIterator.remove();
}
Could you help me with that?
Here is example code:
<h:form id="mainForm">
<h:selectOneMenu required="true" id="dictionaryValueId" value="#{SomeBean.dictionarySelectedValue}">
<f:selectItem itemValue="#{null}" itemLabel="#{i18n['view.choose']}" />
<f:selectItems value="#{SomeBeanBean.dictionaryValuesMap}" var="element"
itemLabel="#{element.descripption}" itemValue="#{element.key}" />
<f:ajax event="change" execute="#this msgId" render="msgId dictionaryValueId"/>
</h:selectOneMenu>
<h:message id="msgId" style="display:none;" for="dictionaryValueId" />
...
<h:commandButton value="#{i18n['button.forward.name']}"
actionListener="#{SomeBean.forward}" >
<p:ajax process="#form" update="mainForm"/>
</h:commandButton>
I am not sure, but is not there a problem with
style="display:none;"
for
<h:message id="msgId"/>
You can wrap your message with <h:panelGroup/> and render by this panelGroup Id, this Id will be always present on your form.
<h:form id="mainForm">
<h:selectOneMenu required="true" id="dictionaryValueId" value="#{SomeBean.dictionarySelectedValue}">
<f:selectItem itemValue="#{null}" itemLabel="#{i18n['view.choose']}" />
<f:selectItems value="#{SomeBeanBean.dictionaryValuesMap}" var="element" itemLabel="#{element.descripption}" itemValue="#{element.key}" />
<f:ajax event="change" execute="#this" render="messageBundle1 dictionaryValueId"/>
</h:selectOneMenu>
<h:panelGroup id="messageBundle1">
<h:message id="msgId" style="display:none;" for="dictionaryValueId" />
</h:panelGroup>
<h:commandButton value="#{i18n['button.forward.name']}"
actionListener="#{SomeBean.forward}" >
<p:ajax process="#form" update="mainForm"/>
</h:commandButton>
</h:form>
With the value I get from my combobox, I need to unlock 1 of the elements (inputText) and block the other:e.g
if selecOnMenu value is "A" then inputText with idA is unlocked and the other's blocked
xhtml code:
<h:form prependId="false">
<p:selectOneMenu id="enviado" value="#{combo.valor}">
<f:ajax event="change" execute="enviado" render="saida" />
<f:selectItem itemValue="#{null}" itemLabel="Selecione um item" />
<f:selectItems value="#{combo.disponiveis}" />
</p:selectOneMenu>
<br></br>
<h:outputText id="saida" value="opção: #{combo.valor}" />
<div>
<p> Opção A -- Falta implementar</p>
<p:inputText id="idA" value="Insira texto aqui" disabled="??????" />
</div>
<div>
<p>Opção B -- Flta implementar</p>
<p:inputText id="idB" value="Insira texto aqui" disabled="??????" />
</div>
</h:form>
</h:body>
</html>
UPDATE:
I make it work now using on disable = "#{combo.valor != 'idB'}"
now only need to make the ajax work with it
UPDATE 2:
Well, when using <p:inputText> didn't work, but with <h:inputText> works fine.
UPDATE 3:
I just need to use the right ajax element, i was using jsf just trying to re-render a primefaces element, with the primeFaces ajax worked
Thank you
<h:form action="" prependId="false">
<h:selectOneRadio value="#{managedBean.color}" id="color">
<f:selectItem itemValue="red" itemLabel="Color1 - Red" />
<f:selectItem itemValue="green" itemLabel="Color1 - Green" />
<f:ajax event="click" render="group1" listener="#{managedBean.renderSubQuestions}"/>
</h:selectOneRadio>
<h:panelGroup id="group1">
<h:outputLabel value=" Color Description " rendered="#{managedBean.colorRender}"></h:outputLabel>
<h:inputText rendered="#{managedBean.colorRender}"></h:inputText>
<h:selectOneRadio id="number" value="#{managedBean.integer}" rendered="#{managedBean.colorRender}" >
<f:selectItem itemValue="1" itemLabel="Number1 - 1" />
<f:selectItem itemValue="2" itemLabel="Number1 - 2" />
<f:selectItem itemValue="3" itemLabel="Number1 - 3" />
<f:ajax event="click" render="group2 " listener="#{managedBean.renderSubQuestions}"/>
</h:selectOneRadio>
</h:panelGroup>
<h:panelGroup id="group2">
<h:outputLabel value="Number Description " rendered="#{managedBean.integerRender}"></h:outputLabel>
<h:inputText rendered="#{managedBean.integerRender}"></h:inputText>
</h:panelGroup>
</h:form>
In my scenario I used nested JSF AJAX with nested rendered attribute. If I select a color based on the selection, it rendered some radio button (addition elements) with AJAX. It is working fine, but additional elements with AJAX behavior is not working for me. If I remove rendered attribute in number radio button, it is working fine. I dont know where I did mistake.
It is most likely what your ManagedBean is not in ViewScoped or SessionScoped. When you post back to the bean, you are loosing rendered states. I suggest to change for the ViewScoped one.
Not related :
You should remove the action attribute from the h:form since JSF override it.
I'm using tomahawk <t:selectOneRadio> as follows:
<t:selectOneRadio
id="sorid" onclick="myForm.submit();"
value="#{myBean.property}" style="float: left;padding-right: 5px;">
<f:selectItem itemLabel="#{bundle.option_1}"
itemValue="option1" id="option1" />
<f:selectItem itemLabel="#{bundle.option_2}"
itemValue="option2" id="option2" />
<f:selectItem itemLabel="#{bundle.option_3}"
itemValue="option3" id="option3" />
<a4j:support event="oncomplete" reRender="chart"/>
</t:selectOneRadio>
The form is submited but the backing bean property is never changed. This only happens in IE wether or not I give extra clicks on the page. I've tried with event="onclick" also. I've tried adding this.blur(); to the selectOneRadio onclick actions.
Any help will be appreciated!
Thanks.
Remove the onclick handler. It's only colliding with Ajax support. Just let <a4j:support> do the job instead during the click event.
<t:selectOneRadio
id="sorid"
value="#{myBean.property}" style="float: left;padding-right: 5px;">
<f:selectItem itemLabel="#{bundle.option_1}"
itemValue="option1" id="option1" />
<f:selectItem itemLabel="#{bundle.option_2}"
itemValue="option2" id="option2" />
<f:selectItem itemLabel="#{bundle.option_3}"
itemValue="option3" id="option3" />
<a4j:support event="click" reRender="chart"/>
</t:selectOneRadio>
(note that the event name does by itself not have the on prefix, this only applies to attribute names of the HTML elements which should refer a script which should be executed when the event occurs)