Change flowScope value with commandButton - jsf

I've a boolean variable in my view-state:
<set name="flowScope.render" value="false" type="java.lang.Boolean" />
Now i render a commandButton with this variable
<p:commandButton value="Show Dates"
rendered="#{!render}"
update="table1,buttons" />
Now i want to change the value of the variable with a click on this commandButton. I tried the setPropertyActionListener, but it doesn't work:
<p:commandButton value="Show Dates" rendered="#{!render}" update="table1,buttons">
<f:setPropertyActionListener value="true" target="#{render}" />
</p:commandButton>
I don't find much about how to change the value. So how is this possible?

Now i figured it out.
I must work with transitions. In the same view-state where the variable is set, there i define two transitions:
<transition on="rendertrue">
<set name="flowScope.render" value="true" type="java.lang.Boolean" />
</transition>
<transition on="renderfalse">
<set name="flowScope.render" value="false" type="java.lang.Boolean" />
</transition>
I don't change the value of the exist variable, i just overwrite it. If this is the best or cleanes solution, i don't know, but it works.
Now i call the specific transition with the action statement in the commandButton:
<p:commandButton value="Show Date"
rendered="#{!render}" update="table1,buttons"
action="rendertrue" />
<p:commandButton value="Hide Date"
rendered="#{render}" update="table1,buttons"
action="renderfalse" />

Related

PrimeFaces p:selectOneRadio to be set false on double click

My project requirement is to set p:selectOneRadio false as default value.
On single click p:selectOneRadio to be set as true and on double click
p:selectOneRadio should be set false.
<p:selectOneRadio id="#{project.uampaiid}_createUser_access_radiobutton" value="#{dataAccess.accessRadio}"
layout="pageDirection"
rendered="#{dataAccess.accessRadioSelection}" disabled="#{dataAccess.disableAccessField}"
requiredMessage="Please Assign a Access for every role" onchange="reactToChangedRadio(this)" >
<f:selectItems value="#{dataAccess.roleUserList}" var="accessUser"
itemLabel="#{accessUser.role}"
itemValue="#{accessUser.roleId}.#{dataAccess.accessId}" />
</p:selectOneRadio>
To perform a double click in a p:selectOneRadio you can work with a commandLink
It will look like this
<h:commandLink id="commandLink" >
<p:ajax event="dblclick" listener="#{managedBean.someMethod()}" />
<p:selectOneRadio id="radioButton" value="#{managedBean.example}" >
<f:selectItem itemLabel="True" itemValue="True" />
<f:selectItem itemLabel="False" itemValue="False" />
</p:selectOneRadio>
</h:commandLink>
Hope that helped you.

h:panelGrid inconsistent allocation of cells

My page: ---
Something is causing panelGrid to create an empty cell in several rows.
I'd like to have a visible two column table, first column a label, second column an inputText element or a selectMenu with a tooltip.
My workaround was this, create a 3 column table, and when panelGrid decides not to create an empty cell, add a <br></br> to prompt it to do so.
<h:panelGrid columns="3" style="text-align:left">
<p:remoteCommand name="startJobActivate" actionListener="#{provisioningBean.startJobActivate}" />
<h:outputLabel for="longitudeIdAct" value="Longitude: " />
<p:inputText id="longitudeIdAct" value="#{provisioningBean.longitude}" title="Longitude" />
<p:watermark for="longitudeIdAct" value="Longitude" />
<h:outputLabel id="equipmentDropMenuActLabel" for="equipmentDropMenuAct" value="#{provisioningBean.accessDeviceLabel}" />
<p:selectOneMenu id="equipmentDropMenuAct" value="#{provisioningBean.equipment}" title="Not needed for CSI or SIP"
disabled="#{provisioningBean.equipDisabled}" style="width: 100% !important">
<f:selectItem itemLabel=" Equipment" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{provisioningBean.equipments}" />
</p:selectOneMenu>
<p:tooltip for="equipmentDropMenuAct" />
<h:outputLabel for="rangeActId" value="Range: " />
<p:spinner id="rangeActId" value="#{provisioningBean.rangeAct}" min="1" title="Amount of telephone numbers to provide" size="3"
disabled="#{provisioningBean.rangeDisabled}" />
<br></br>
</h:panelGrid>
Is this a bug?
What am I missing here?
EDIT:
Oh neat! I managed to create a minimal example and it still has the same issue :D https://gist.github.com/WurmD/f3cb45669e6871acc77462f34891862f
screenshot - you need 10 rep to post images
So this is a 3 column h:panelGrid, but the third cell is being taken up by something
EDIT2: Same behavior with p:panelGrid
Thank you Kukeltje for this answer:
h:panelGrid columns="3" signify "start new row after each third element"
Thus, either put the watermarks (and other invisible elements) outside h:panelGrid, or use h:panelGroup to groups things that should only occupy one cell in the table:
<p:remoteCommand name="startJobActivate" actionListener="#{provisioningBean.startJobActivate}" />
<p:panelGrid columns="2" style="text-align:left">
<h:outputLabel for="orderIdAct" value="Order Number: *" />
<p:inputText id="orderIdAct" value="#{provisioningBean.orderNumberAct}" label="orderId" title="Order Number" />
<h:outputLabel for="customerNameIdAct" value="Customer: *" />
<h:panelGroup>
<!-- h:panelGroup to group things that should only occupy 1 cell in the table -->
<p:inputText id="customerNameIdAct" value="#{provisioningBean.customerName}" title="Customer Name" />
<p:watermark for="customerNameIdAct" value="Customer Name" id="watermarkcustomerNameIdAct" />
</h:panelGroup>
</p:panelGrid>
<p:panel id="executePanelAct">
<p:commandButton value="Execute Activation" id="actvateButton" update=":form:growl" styleClass="executeButton" />
</p:panel>
<!-- Items that don't need to be in panelGrid -->
<p:watermark for="orderIdAct" value="Order Number" id="watermarkorderIdAct" />

Aligning Radio Button in a JSP/JSF with its label

I would like to achieve the following in a JSF1.1 environment:
Gender: RadioButtonForFemale FEMALE RadioButtonForMale MALE
<h:panelGroup>
<h:outputLabel for = "searchSex" value = "#{bundle.Sex_Label}" style ="width:15%;">
</h:outputLabel>
<h:selectOneRadio id="searchSex" value="#{yy.search_Sex}" style="verticle-align:top;font-size:95%;color:red;">
<f:selectItem itemLabel="F" itemValue="F" />
<f:selectItem itemLabel="M" itemValue="M"/>
</h:selectOneRadio>
</h:panelGroup>
Basically, all the radio button should be in the same row as the lable (Gender in our case).
Attached is my current code. the radio button appear in the next row. My PanelGrid has 1 column.
thanks,
Indeed, the <h:selectOneRadio> generates a <table> which is by default a HTML block element (i.e. always starts at a new line).
You'd need to set the CSS display property to inline-table.
<h:panelGroup>
<h:outputLabel for="searchSex" value="#{bundle.Sex_Label}" style="width: 15%;" />
<h:selectOneRadio id="searchSex" value="#{yy.search_Sex}" style="display: inline-table; verticle-align: top; font-size: 95%; color: red;">
<f:selectItem itemLabel="F" itemValue="F" />
<f:selectItem itemLabel="M" itemValue="M" />
</h:selectOneRadio>
</h:panelGroup>
But this is pretty clumsy. If you're already using a <h:panelGrid>, I'd recommend to just set its columns to 2 so that you can have labels in left column and inputs in right column.
<h:panelGrid columns="2">
<h:outputLabel for="searchSex" value="#{bundle.label_sex}" />
<h:selectOneRadio id="searchSex" value="#{yy.searchSex}">
<f:selectItem itemLabel="F" itemValue="F" />
<f:selectItem itemLabel="M" itemValue="M" />
</h:selectOneRadio>
<h:outputLabel for="somethingElse" value="Something else" />
<h:inputText id="somethingElse" value="#{yy.somethingElse}" />
...
</h:panelGrid>

Dynamic Columns into ui:define

I have a data table in an xhtml with "ui:insert" space...
In another xhtml i use ui:define to add some columns... the problem is that i have dynamic columns to insert..
i've already tryed with a4j:repeat, ui:repeat, c:foreach and rich:columns...
<rich:columns value="#{entity.dadosAdicionais}" var="col" >
<h:outputText value="#{col.valor}" escape="false" />
<h:outputText value="#{col.nome}" />
</rich:columns>
someone knows whats the problem with ui and rich components?
may be you can try like this.
<rich:columns value="#{entity.dadosAdicionais}" var="col" index="index">
<f:facet name="header">
<h:outputText value="#{col.valor}" />
</f:facet>
<h:outputText value="#{model[index].model}" />
</rich:columns>
value= the modelValue for column.

How to break in a <ui:repeat>

Is there any easy way I can break in a ui:repeat loop ?
I'm trying to do it the following way, but it does not work. The idea is to print the image when, requestScope.counter == 1.
<c:set target="#{requestScope}" property="counter" value="0" />
<ui:repeat var="mediaVar" value="#{brandsVar.brandBrandMedia}" >
<ui:fragment rendered="#{mediaVar.bmType eq 'image'}">
<ui:param name="#{requestScope.counter}" value="#{requestScope.counter + 1}" />
</ui:fragment>
<h:graphicImage rendered="#{mediaVar.bmType eq 'image' && requestScope.counter == 1}"
height="100" width="100"
value="location of image" />
</ui:repeat>
You can't break in an ui:repeat. As to your concrete problem, use and instead of &&.

Resources