update model value although failing validation phase - java

First of all, I'm under JSF 1.2, RichFaces 3.3.0 and Tomahawk 1.1.9.
I have a rich:tabPanel which contains one form in each tab:
<h:form>
// This manages error messages thrown by my application:
<jsp:include page="showError.jsp" flush="true" />
<rich:tabPanel switchType="client" selectedTab="#{MyBean.selectedTab}">
<rich:tab name="tab1" label="TAB-1">
<t:subform id="subForm1">
//Some components such as h:inputText and h:selectOneMenu
<t:commandButton actionFor="subform1" action="#{BeanForm1.insertData}" value="INSERT">
<f:setPropertyActionListener target="#{MyBean.selectedTab}" value="tab1" />
</t:commandButton>
</t:subform>
</rich:tab>
<rich:tab name="tab2" label="TAB-2">
<t:subform id="subForm2">
//Some components such as h:inputText and h:selectOneMenu
<t:commandButton actionFor="subform2" action="#{BeanForm2.insertData}" value="INSERT">
<f:setPropertyActionListener target="#{MyBean.selectedTab}" value="tab2" />
</t:commandButton>
</t:subform>
</rich:tab>
</rich:tabPanel>
I want the application to keep the view in the tab where the user has submit the subform, even if it hasn't passed the validations I've defined. At this time, the 'MyBean.selectedTab` value only changes when the subform has been validated and submitted.
Is there any way to force this change even if the form fails the validations? Maybe I'm not focusing the problem in the proper way, how can I get this behaviour?
Thanks in advance.

Related

Not able to render the parent panel group component with <p:ajax>

I am using primefaces autocomplete in my application to suggest userIds to the User.Once user enters three characters into the Autocomplete textbox my UserIds list will be suggested to the user to Autocomplete. As soon as user selects userId from List, I am updating the User First and Last name in the Output Text in the following format John Doe(jd123) with a Delete button beside to this name. As shown in comments in the code first ajax request is perfectly working fine.But When I am trying to delete name that I am printing using <h:outputText/> I am getting an error which is
javax.faces.FacesException: Cannot find component with identifier
"items" referenced from "j_idt34:0:imgid".
My Code :
<h:outputLabel value="Select user" for="acMinLength" />
<p:autoComplete id="acMinLength"
minQueryLength="3"
value="#{autoCompleteBean.txt2}"
completeMethod="#{autoCompleteBean.complete}">
<p:ajax event="itemSelect"
listener="#{autoCompleteBean.handleSelect}"
update="items"/> // First Ajax request perfectly working fine
</p:autoComplete>
<h:outputLabel value="selectedUsers" for="acMinLength" />
<h:panelGroup id="items">
<ui:repeat value="#{autoCompleteBean.printId}" var="item">
<h:outputText value="#{item}"/>
<h:graphicImage name="delete.png" library="images" id="imgid">
<p:ajax event="click"
listener="#{autoCompleteBean.updateList}"
update="items"/> // This is where i am getting exception
</ui:repeat>
<h:panelGroup>
I know I can update the parent component with child Ajax request. But I don't know what I am doing wrong.
it should be safer to update the h:form component. I'm not sure you can update every h: component by id. If you open the resulting xhtml and try checking the actual id path of the children components, you will see that the don't include the ids of all of their parent's component. Some id's are skipped
However, you can try this
update=":#{p:component('items')}"
Hope it helps
After a rigorous search I tried the answer posted by andre here(Primefaces - Cannot find component with identifier outside the datatable) and hurray it's working.
like this
update="#([id$=items])"

JSF f:ajax and IE 8

I encountered with problem: in IE8 don't work event in f:ajax and don't update other components after change value.
<h:selectBooleanCheckbox id="someId"
value="#{someBean.showEmpty}"
title="#{i18n['button.showEmpty']}">
<f:ajax event="change"
listener="#{someBean.changeShowEmpty}"
execute=":someForm #form" render=":messages :someForm #form" />
</h:selectBooleanCheckbox>
In Chrome, Opera, Firefox - it works.
Thanks for the help.
That's indeed "expected" behaviour for MSIE. It will only work on 2nd change and forth, because MSIE thinks that the 1st click is in essence not a change. You should be listening on the click event instead. That's also exactly what the <f:ajax> already by default does for a <h:selectBooleanCheckbox>. Just remove the event attribute altogether.
<f:ajax listener="#{someBean.changeShowEmpty}"
execute=":someForm #form" render=":messages :someForm #form" />
The <f:ajax event> defaults to "valueChange" in UIInput components and defaults to "action" in UICommand components. In UIInput components which generate radio button or checkbox, it will then generate onclick. In other UIInput components (text fields, textarea, dropdowns, etc) it will generate onchange.
Unrelated to the concrete problem, an other <h:form> can not be processed in contrary to what you seem to think in execute attribute, simply because its values are not submitted along with the submit of the current form. But that's another story.

primefaces p:message outside the components form

I'm using JSF 2.0 and Primefaces 3.2.
I'm using Facelets for templating, and I've built a 3-column layout:
Left column - mainContent column - Right column. Each column got it's own template xhtml file with ui:composition which I insert in a mainTemplate.
In the mainContent column I've got a info-button (p:commandButton):
<h:form id="mainForm">
<p:commandButton id="infoButton" value="Info" actionListener="#{faceletsAttachment.addInfo}"/>
</h:form>
But I want the info to show in the right column, with a
<h:form id="rightColumnForm">
<p:message for="infoButton">
</h:form>
This obviously does not work, because does not find the infoButton. Any idea how I can make this work? I tried
<p:message for="mainForm:infoButton">
too, but no cigar.
The reason I want to use a p:message is that I want the message to position itself on the y-position the infoButton has. If you got an alternative solution to how I can do this, I would also appreciate it.
If you are adding messages manually from server side you can do the following
<p:message id="myInfoButton" for="myInfoButton" />
and send messages from server to myInfoButton like this
FacesContext.getCurrentInstance.addMessage("myInfoButton ", new FacesMessage("My Message", "Some Text goes here..."));
also add :rightColumnForm id to update of the <p:commandButton id="infoButton"

I need a button that performs an action but doesn't trigger validation or refreshes the page(JSF 2.0)

I need you to recommend me a JSF component that can help in the following scenario(I will first paste an image that will help me explain):
This page that you see in the image is a registration page, each of the panels have different fields and gadgets, when the register button is clicked, a new user is saved into the database.
The problem i have is in the show buttons. The buttons on top of each panel when clicked should display one panel and hide the other, but they must not trigger the field validation.
I use field validation by the attribute "validator"(in combination with a backing bean method) that most of JSF input fields have.
Currently everything that you see there is inside one h:form.
-what should i do to display a panel and hide the other without triggering the validation of the panel that is hiding?
-Is there another alternative to the h:commandLink or h:commandButton(they trigger the validation)?
-Putting each panel in a different h:form can do the trick?(Is that permited?)
-What do you think would be the best approach?
Use p:tabView Of primefaces, then put your contents(registration panels) in separate tab, use separate form for both of the tab, it will solve your problem....
e.g.
<p:tabView>
<p:tab title="panel1">
<h:form id="form1" prependId="false">
<h:inputText label="Sample Label"/>
<p:commandButton value="register"/>
</h:form>
</p:tab>
<p:tab title="panel2">
<h:form id="form2" prependId="false">
<h:inputText label="Sample Label"/>
<p:commandButton value="register"/>
</h:form>
</p:tab>
</p:tabView>
-what should i do to display a panel and hide the other without triggering the validation of the panel that is hiding?
Use two h:form
s there another alternative to the h:commandLink or h:commandButton(they trigger the validation)?
to make POST you must only use them
I would have used rich:modalpanel for this purpose
For the panel's toggle, Why don't you use JavaScript?
<h:commandButton value="Show panel 1" onclick="$('#panel1').hide();$('#panel2').show();return false;"/>
The return false will restrict the page from submitting, hence page won't refresh and since no data is posted back to server, validation phase will never execute.
Bottom line : IMHO this can be handled at client side itself.
You are aware of the immediate attribute, allowing to refresh without changing data.
Unfortunately it doesn't remember changes entered, so you might end up in the validation explicitly being done in your action instead of by JSF itself.

JSF - 2 a4j:actionParam in one commandlink bug

I have such structure in my jsp:
<h:commandLink action=#{docbean.save}>
<a4j:actionParam name="somename" value="bill_all" assignTo="#{billdoc.billType}"/>
<a4j:actionParam name="somename" value="bill_document" assignTo="#{docbean.doctype}"/>
</h:commandLink>
While debugging i saw, that billdoc.billtype and docbean.doctype have the same values: "bill_document".
Is it bug? If not, then how can i put value to my managed-bean?
UPDATED:
Found the answer:
I had two actionParams with one name. ActionParam is f:actionListener + f:param. So, if you have several actionparams with one name, you will have the problem i had. RichFaces and JSF doesn't warn you about it.
First, you need a space here <a4j:actionParamvalue - before value
Second, You may try this instead of <a4j:actionParam>:
<f:setPropertyActionListener value="bill_all" target="#{billdoc.billType}" />
You may need to put immediate="true" on your commandLink if there are validation errors in your form. You can view these errors by adding <rich:messages /> ontop of the page.
Try using an a4j:commandLink. Or - if you stick to h:commandLink - try embedding your a4j:actionParams in an a4j:support tag.

Categories

Resources