Same space between 2 inputText boxes using JSF and CSS - css

I want to create a JSF form where users can write their name and surname and validate them using JSF validators. The problem is that I would like to set the same space between the 2 inputText boxes in the form, in both cases, when the typed data is correct according to the validator, and when it is not correct. So if between the 2 inputText boxes there are X pixels if the user has not typed anything, when typed name is not correct, the error showing message should be displayed between the 2 inputText boxes and the pixels between them should be also X px. I suppose this is a CSS issue, but I am unable to get it, so any help would be appreciated.
Here is my code
<h:form>
<p:panel id="panelregister">
<h:panelGrid columns="1">
<!--Name-->
<p:inputText id="name" label="name" size="32" maxlength="9"
value="#{mManagedBean.name}">
<f:validator validatorId="packagevalidators.NameValidator"/>
</p:inputText>
<p:watermark for="name" value="Name (*)" />
<p:message for="name"/>
<!--Surname-->
<p:inputText id="surname" label="surname" required="true" size="32" maxlength="9"
value="#{mManagedBean.surname}"
requiredMessage="Must enter a surname">
<f:validator validatorId="packagevalidators.SurnameValidator"/>
</p:inputText>
<p:watermark for="surname" value="Surname (*)" />
<p:message for="surname" />
<p:commandButton value="Submit" action="#{mManagedBean.save}" ajax="false" />
</h:panelGrid>
</p:panel>
</h:form>

You are using h:panelGrid which renders as HTML <table>.
p:message will be rendered as div and by default that div won't have any content so it won't take any space you provide.
One way to do this is to use a h:panelGroup around it and give pre defined height of p:message
Example:
<h:panelGroup layout="block" style="height:27px">
<p:message for="name" />
</h:panelGroup>

Related

How to globally style all PrimeFaces input components having set required="true"

As an example, think about the following simple form with primefaces input components some of which are required:
<h:form id="person">
<h:panelGrid columns="2">
<p:outputLabel for="inputFN" value="First Name"
indicateRequired="auto" />
<p:inputText id="inputFN" required="true"
placeholder="First Name right here please." />
<p:outputLabel for="inputLN" value="Last Name"
indicateRequired="auto" />
<p:inputText id="inputLN" required="true"
placeholder="Last Name right here please." />
<p:outputLabel for="inputBD" value="Date of Birht"
indicateRequired="auto" />
<p:calendar id="inputBD" required="false"
placeholder="Please kindly let us know the very starting point in time of your existence!" />
<p:outputLabel for="inputFC" value="Favourite Color"
indicateRequired="auto" />
<p:inputText id="inputFC" required="false"
placeholder="What is your favourite colour?? Green? Yellow? Please!" />
<p:outputLabel for="inputFH" value="Favourite Hobby"
indicateRequired="auto" />
<p:autoComplete id="inputFH" required="true"
placeholder="Your favourite hobby? Stackoverflow I bet!" />
</h:panelGrid>
(*) these fields are vital! Don't even think about submission when empty!
</h:form>
The rendered output of inputFN (required), inputFC (not required) and inputFH (required) looks like this:
<input id="person:inputFN" name="person:inputFN" type="text" placeholder="First Name ..." aria-required="true"
class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all"
role="textbox" aria-disabled="false" aria-readonly="false">
<input id="person:inputFC" name="person:inputFC" type="text" placeholder="What is your favourite colour?..."
class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all"
role="textbox" aria-disabled="false" aria-readonly="false">
<input id="person:inputFH_input" name="person:inputFH_input" type="text"
class="ui-autocomplete-input ui-inputfield ui-widget ui-state-default ui-corner-all ui-state-error"
autocomplete="off" placeholder="Your hobby? ..." value="" role="textbox"
aria-disabled="false" aria-readonly="false" aria-autocomplete="list">
I don't see a chance to have a CSS selector catching only the required fields. Note that not all required components get the aria-required="true" suggested to use by #Malloware. For example the p:autocomplete inputFH doesn't.
As we have plenty of input components distributed in views and (nested) composite components and the required attribute is sometimes determined dynamically plus I am lazy, I'd like to not touch each and every component and add a styleClass="#{something.isRequired ? 'required' : ''}" to it.
Is there a clean way to globally enable client side distinction of required vs optional fields?
What I finally want to achive is to highlight the placeholders (using the ::placeholder CSS selector) of all required fields by color, as an addition to the indicateRequired kindly provided by p:outputLabel.
Just use this CSS selector. Gauranteed to work for all PF input fields for PF 7.0or higher.
input[aria-required="true"] {
color: red;
}

p:selectCheckboxMenu Dynamic CSS

I have populated multi select drop down list , i have a scenario like the color of the text in the dropdown should differ based on some condtions . i have populated the values in <f:selectItems>. I have attached the screen shot of the drop down by adding css to rendered html file. How could i add dynamic css for the label
xhtml :
<p:selectCheckboxMenu id="stackListDropDown" filter="true"
style="vertical-align:middle" filterMatchMode="contains"
value="#{stackListForPOCBean.selectedStackListFromDB}"
styleClass="help-inline selectOneMenuDefault">
<!-- <f:selectItem noSelectionOption="false" /> -->
<!-- <p:ajax event="change" process="#this"
listener="#{stackListForPOCBean.subjectSelectionChanged(stack)}" /> -->
<f:selectItems value="#{stackListForPOCBean.stackListFromDB}"
var="stack" itemLabel="#{stack.stackId} - #{stack.stackDesc}"
itemValue="#{stack.stackId}">
</f:selectItems>
<p:ajax update="stackLineGroup" process="#this "
listener="#{stackListForPOCBean.validateMultiSelectStackForPOC()}" />
<p:ajax event="toggleSelect" update="#this stackLineGroup"
listener="#{stackListForPOCBean.validateMultiSelectStackForPOC()}" />
</p:selectCheckboxMenu>
Expected Result using primefaces
I achieved it by the following code,changed to selectManyMenu and added checkbox true
<p:selectManyMenu id="stackListDropDown"
styleClass="help-inline selectOneMenuManyDefault"
value="#{stackListForPOCBean.stackListSelected}" var="t"
filter="true" filterMatchMode="contains" showCheckbox="true">
<f:selectItems value="#{stackListForPOCBean.stackListFromDB}"
var="stack" itemLabel="#{stack.stackId} - #{stack.stackDesc}"
itemValue="#{stack}" />
<p:column>
<h:outputText value="#{t.stackId} - #{t.stackDesc}"
styleClass="#{t.stackColorStyle}" />
</p:column>
<p:ajax update="stackLineGroup" process="#this "
listener="#{stackListForPOCBean.validateMultiSelectStackForPOC()}" />
</p:selectManyMenu>

how to make richfaces popup the popuppanel upwards

The link contains an example of richfaces 4 popuppanel:
richfaces popuppanel example
Here is the code:
<rich:toolbar height="26px" id="tb">
<rich:toolbarGroup location="right">
<h:outputLink value="#">
<rich:componentControl event="click" operation="show" target="ls">
<a4j:param name="event" value="event" noEscape="true" />
<rich:hashParam>
<a4j:param noEscape="true" name="top"
value="jQuery(#{rich:element('tb')}).offset().top + jQuery(#{rich:element('tb')}).height()" />
<a4j:param noEscape="true" name="left"
value="jQuery(#{rich:element('tb')}).offset().left + jQuery(#{rich:element('tb')}).width() - p_width" />
</rich:hashParam>
</rich:componentControl>
Search
</h:outputLink>
</rich:toolbarGroup>
</rich:toolbar>
<rich:popupPanel header="Enter Search Terms" id="ls" autosized="true" modal="false" moveable="false" resizeable="false" followByScroll="false" >
<h:panelGrid columns="3">
<h:outputText value="Search:" />
<h:inputText />
<h:outputLink onclick="#{rich:component('ls')}.hide(event); return false;" value="#">Search
</h:outputLink>
</h:panelGrid>
</rich:popupPanel>
<h:outputScript type="text/javascript" target="body">
p_width = #{rich:component('ls')}.width();
</h:outputScript>
But the popup is appearing in random places, i.e. sometimes under the bar, and then have to scroll and sometimes above. Is it possible to make sure it always appears right above the bar while being attached to it?
The top and left parameters set the position of the panel, change them to where you want the panel to be, or call the method directly:
RichFaces.component('panelId').show(null, {top: "800px", left: "500px"})
You're using the part of the example that specifically sets the panel under the bar so it shouldn't be surprising when the panel appears there.

Scrollbar for outputLabel

I want to implment a scrollbar for a outputLabel but if i use scrollbar component it put every list elment in a new row. The whole output should be disyplayed in one row and the list should be scrollable. Can i fix this problem with a CSS attribute?
i use primefaces 4.0 and jsf 2.1
here is my code
<p:commandButton id="newMessage" update=":contentForm"
actionListener="#{taskboxBean.newMessage}" value="New Message" />
<p:commandButton id="trash"
update=":contentForm, :postForm:tabViewPosts:trashTable, :postForm:tabViewPosts:inboxTable, :postForm:tabViewPosts:sentTable"
actionListener="#{taskboxBean.deleteSelectedTaskbox}" icon="ui-icon-trash" title="Trash" />
<p:scrollPanel>
<ui:repeat var="task_to_user" value="#{taskboxBean.selectedTaskbox.TASKBOX_TO_USERS}">
<p:outputLabel
value="#{task_to_user.USER.EMAIL} #{task_to_user.USER.FIRST_NAME} #{task_to_user.USER.LAST_NAME} #{task_to_user.USER.FIRST_NAME}" />
</ui:repeat>
</p:scrollPanel>
<h:outputText value="#{taskboxBean.selectedTaskbox.TASKTYPE.NAME} " />
<h:outputText value="#{taskboxBean.selectedTaskbox.CREATE_TIMESTAMP} " />

insert markup into h:outputText to enhance some words jsf

I would like to insert a <span> into the value of this outputText :
<h:outputText id="jesuis1" value="la quantité nécéssaire : #{editCommandController.myCom.nbreExemplaire*editCommandController.myCom.nbrePage}" />
my goal is to enhance this {editCommandController.myCom.nbreExemplaire*editCommandController.myCom.nbrePage} by css but it generated an error
do you have any idea
You need the escape attribute!
<h:outputText escape="false" value="#any text including el that
evaluates to html tags"/>
or you could use
<h:outputFormat escape="true" value="text with {0} tags>
<f:param value="#{bean.htmlExpression}" />
</h:outputFormat>

Resources