How can I use (eg ajax) to show a specific jsf element if I click the button where the ajax tag belongs to? But without having to use any backing bean, just by JSF components without JavaScript?
Is that possible?
Luiggi is right , You better use js for client side toggling
But ,
I think you can bind like this
<h:inputText id="first" binding="#{someViewButNonManagedBeanObject}"`...
and than
<h:inputText id="second" render="#{no empty someViewButNonManagedBeanObject}"`...
or
<h:inputText id="second" render="#{someViewButNonManagedBeanObject.value eq 'wow'}"`...
(Not tested)
Related
I'm using JSF 1.1 in WAS 5 (Websphere Application Server 5), and I need to know what Column in my HtmlDataTable was clicked, I have tried by many ways but I can not get a Success result, the only thing I need is to pass a parammeter to an action.
I have something like
<h:form>
<h:datatable value=#{bean.list} var="row">
<h:column>
<f:facet name="header">
<h:outputText value=""/>
</f:facet>
<h:commandButton value="Test!" action="#{bean.saludar}">
<f:param name="cod" value="#1"/>
</h:commandButton>
</h:column>
</h:datatable>
</h:form>
In my BackingBean I have
public class Bean {
......
......
public String saludar() {
FacesContext context = FacesContext.getCurrentInstance();
Object value = context.getExternalContext().getRequestMap().get("cod");
//value IS NULL !!!!!!!!!!!!!!!!!!! HELP HERE OR BEFORE ....
}
}
I have tried many ways, I don't know if the problem is because I am inside a HtmlDataTable or something like that, I can know the selected Row by binding de table to one HtmlDataTable and accesing to the method table.getRowData(); I have almost 3 days And i can not find a solution, I have tested in JSF 1.2 With Glassfish 3.1 and it worked, but I dont know how to get work that in WAS 5 with Java 1.4
Thnkxx !!
In JSF 1.x, the <f:param> is not supported in command buttons. This support is since JSF 2.0 only.
There are several ways to achieve your concrete requirement (btw, the requirement to know the clicked column is quite strange, perhaps you actually meant "row" when you said "column"?).
Use <h:commandLink> instead of <h:commandButton>. It supports <f:param>.
Use <f:setPropertyActionListener> instead of <f:param>.
Use UIData#getRowData() or DataModel#getRowData() instead to obtain the current row.
Install JBoss EL and just pass the row itself directly like so action="#{bean.saludar(row)}".
See also:
Communication in JSF
Using datatables (in JSF 1.x)
Invoking methods with parameters by EL in JSF 1.2
in a brief word here is the problem
when i value change of the menu it execute the post-constructor again in backing bean then execute method fillAreas and i used view scope .
<p:selectOneMenu id="governate" value="#{add.selectedGovern}" style="height:26px; text-align: right; width: 303px;"
valueChangeListener="#{add.fillAreas}" rendered="#{languageBean.isDefaultLanguage==true}" immediate="true" >
<f:selectItem itemLabel="---#{prompts._select} ---" itemValue="0"/>
<f:selectItems value="#{add.governrateList}" var="govern" itemLabel="#{govern.governrateName}" itemValue="#{govern.governrateId}" />
<f:ajax immediate="true"/>
</p:selectOneMenu>
what can i do to prevent calling post-constructor ? and if post-constructor called once why it called every time i select from menu ?
Thanks in advance .
A view scoped bean will be recreated on every single request when a property of it is been bound to an attribute of a taghandler (JSTL <c:forEach>, Facelets <ui:include>, JSF <f:validateXXX>, etc) or to the binding or id attribute of a JSF UI component (<h:someComponent>, etc).
This is related to JSF issue 1492. You could solve it by disabling the partial state saving for the specific view, or by looking for alternate ways to achieve the desired functional requirement.
See also:
Communication in JSF 2.0 - #ViewScoped fails in taghandlers
h:messages component inside a h:form is showing messages related to outside components as well.
How can I restrict it to show messages only related to components inside the containing h:form?
I don't prefer bloating up my code with a separate h:message tag for each & every input component.
Using Primefaces 3.4-SNAPSHOT with JSF 2.2.0-m03
You can make an ajax call to only render the wanted <h:messages.
for example
<h:commandButton value="submit" actionListener="#{fooBean.submit}">
<f:ajax render="msgs"/>
</h:commandButton>
<h:messages id="msgs" globalOnly="true"/>
or in case of primefaces use update attribute in the command button to make the ajax call
JFS1.2 + Richfaces 3.3
Situation is as follows:
JSP page renders conditionally one or another panelGroup.
Within each panelGroup there are couple setters and one command button.
Each of two panelGroups uses own bean for setting and performing action.
On the top of a page there's selectOneRadio with (obvious) two items - coresponding tow options of conditional rendering.
Page renders properly, switcher causes to render appropriate panel.
Case is, commands buttons doesn't call an action.
I know what's going on - when I click a button to call action dom is regenerated, but the value that hold my decision to display particular panel doesn't exist anymore. The button is not recreated, action is not fired.
Technically:
<h:selectOneRadio value="#{reportType}">
<f:selectItem itemLabel="x" itemValue="x"/>
<f:selectItem itemLabel="y" itemValue="y"/>
<a4j:support event="onclick" reRender="xPanel, yPanel/>
</h:selectOneRadio>
<h:panelGrid id="xPanel "columns="2" rendered="#{reportType eq 'x'}">
<...some setters>
<... commandbutton>
</h:panelGrid>
<h:panelGrid id="yPanel "columns="2" rendered="#{reportType eq 'y'}">
<...some setters>
<... commandbutton>
</h:panelGrid>
Question is, how to design the page to obtain proper rendering and actions?
For now, I created additional session bean that holds switching value (x|y), but that desing smells bad for me...
RichFaces 3.3 offers the <a4j:keepAlive> tag which does basically the same as Tomahawk's <t:saveState> and JSF2 #ViewScoped. Add the following line somewhere in your view:
<a4j:keepAlive beanName="#{bean}" />
This will keep the bean alive as long as you're returning null or void from action(listener) methods.
See also:
JSF 1.2: How to keep request scoped managed bean alive across postbacks on same view?
I'm using facelet templating and I think I'm running into an issue with ui:define and the JSF lifecycle. My template.xhtml contains a fixed menu in the header, simplified it has links like this:
<h:commandLink value="Click Me">
<f:ajax update="#{myBean.listener}" render="contentpanel"/>
</h:commandLink>
The template.xhtml also contains a ui:insert statement:
<ui:insert name="content">
<h:outputLabel value="content placeholder"/>
</ui:insert>
Now I have a content.xhtml which looks like:
<ui:composition template="template.xhtml">
<ui:define name="content">
<h:panelGroup id="contentpanel"/>
</ui:define>
</ui:composition>
So much for the introduction. When I click the commandlink 'Click Me' I'm calling my listener. This listener sets a reference in a backingbean to dynamically load the content based on the link I clicked.
This rendering is not done the first time I press the commandlink. Well it basically looks like it first does the re-render and then call the listener instead of the other way around. So when I first click, nothing seems to happen. When I click for the second time I see the content that was set for the first click. When I click for the third time I see the content of the second click.
I think it's because the ui:define view is already re-built in the 'Restore View' phase of the JSF lifecycle. Any ideas on how to overcome this?
UPDATE
Seems like my assumption was wrong. The cause of this seems to be something different. The #{myBean.listener} has a #SessionScoped #ManagedProperty which is updated after the CommandLink is clicked. The contentpanel actually loads data via the #{myBean.data} which is #RequestScoped. This #{myBean.data} did not reload the data correctly. I solved it by passing the getData() method directly to the #SessionScoped bean.
Might be a bit confusing. But my conclusion: it does work to partial render a component which is loaded via facelet templating (ui:define / ui:insert)
Seems like my assumption was wrong. The cause of this seems to be something different. The #{myBean.listener} has a #SessionScoped #ManagedProperty which is updated after the CommandLink is clicked. The contentpanel actually loads data via the #{myBean.data} which is #RequestScoped. This #{myBean.data} did not reload the data correctly. I solved it by passing the getData() method directly to the #SessionScoped bean.
Might be a bit confusing. But my conclusion: it does work to partial render a component which is loaded via facelet templating (ui:define / ui:insert)