How to implement JSF button with image and button label - css

I want to implement JSF button with image and custom label. I tested this code:
<h:commandButton id="savesettings" styleClass="avesettings" value=" Save Settings " action="#{GeneralController.updateDBSettings}" rendered="true" update="growl">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
.avesettings {
background-image: url('../images/small.png');
}
This is the result:
I also tested this second code:
<h:commandButton id="savesettings" image="resources/images/first.png" value=" Save Settings " action="#{GeneralController.updateDBSettings}" rendered="true" update="growl">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
I get this result with no label:
Can you help me to create JSF button with background image and custom label defined as button attribute?

The first method that you have used styleClass="avesettings" i.e., using CSS style is the only possible way to do it since if you specify the image attribute, the input element will become an image.
See also documentation
So your best bet would be to use advanced styling techniques for the buttons, refer to these articles for that:
http://coding.smashingmagazine.com/2009/11/18/designing-css-buttons-techniques-and-resources/
http://www.tyssendesign.com.au/articles/css/styling-form-buttons/

The following JSF/CSS should solve your problem:
JSF (the same as in your first example):
<h:commandButton id="savesettings" styleClass="avesettings" value="Save Settings" action="#{GeneralController.updateDBSettings}" rendered="true" update="growl">
<f:ajax render="#form" execute="#form"></f:ajax>
</h:commandButton>
CSS (adapted):
.avesettings {
background: url('../images/small.png') no-repeat;
cursor: pointer;
width: 126px;
height: 41px;
border: none;
}
Width and height of the css must be the width and height of your image. I also have the css in an external css file, not direct in the JSF template.

Did you try the "image" attribute of he commandButton tag?

One way to implement this is to load the image as jsf resource in your style sheet:
<style type="text/css">
.imageButton
{
background-image:url(#{resource['images/button.png']});
}
</style>
Then set the relevant commandButton styleClass in the xhtml:
<h:commandButton value="Submit" styleClass="imageButton" action="#{...}"/>
Put the file button.png under your resources folder i.e. resources/images/button.png and make sure your resources folder is located next to your WEB-INF folder
Or if you want the image to display as an icon next to the text in the commandButton then you can play around with css a little:
.imageButton
{
padding: ...
border: ...
color: ...
background: [<'background-color'> || <'background-image'> || <'background-repeat'> || <'background-attachment'> || <'background-position'>]
}

Related

how do I apply Style to a Blazor input element

<InputCheckbox class="input-checkbox100" id="ckb1" style="background: #918f8f;" name="remember-me" #bind-Value="CurrentCustomerSubmission.AcceptedTermsAndConditions" />
however when the component is rendered, the color that is being displayed is from the class (input-checkbox100). I am trying to override it for this 1 specific element (so not trying to add it to the CSS).
You can use style tag in your blazor component and override your css class
for example :
#page "/"
<style>
.input-checkbox100{
background: #918f8f;
}
</style>
Give a name to your class here i set ForInput:
<InputCheckbox class="input-checkbox100 ForInput" id="ckb1" name="remember-me" #bind-Value="CurrentCustomerSubmission.AcceptedTermsAndConditions" />
then go to wwwroot go to css and then open app.css and add ForInput in your css with your desire background.
.ForInput{
background: #918f8f;
}

Can we add our own images in primeface's button

In p:button in need add my own image(any image which i want to include).
`<p:button icon="ui-icon-star" title="Icon Only">
</p:button>
`Can i add like this
<p:button icon=""/images/someimage.png"" title="Icon Only">
</p:button>`
The icon attribute of <p:button> needs a CSS class, you can not give it a image path. Example:
PrimeFaces button:
<p:button icon="my-icon" />
CSS:
.my-icon {
background-image: url("images/myicon.png");
}

JSF Primefaces ConfirmDialog

I am working on improving/polishing my primefaces ConfirmDialog but I cant seem to put some nice image on it or improve some of its looks. Also I cant seem to find some documentation on how to use its attributes, I have downloaded the primefaces user manual, but it seem to be missing some things.
Here is my code.
<p:confirmDialog header="Confirm" severity="alert" closeOnEscape="true" widgetVar="confirmationDialog" showEffect="fold" >
<f:facet name="message">
<h:outputText value="Are you sure all details
are correct and proceed in creating the Account?" />
</f:facet>
<p:commandButton value="Yes" actionListener="#{marketingPersonController.create}"
oncomplete="confirmationDialog.hide()" icon="ui-icon-check"
update="propertyPanel accountPanel marketingPersonPanel">
<f:ajax rendered="propertyPanel accountPanel marketingPersonPanel"/>
</p:commandButton>
<p:commandButton value="No" onclick="confirmationDialog.hide()" type="button"
icon="ui-icon-close"/>
</p:confirmDialog>
Here is a screenshot
I cant seem to remove the small ! icon there, if I put severity none, it still shows up a wierd "^" image. I want to completely change the icon and somehow modify some of its look.
Also, I tried having this css. Still its not working.
.ui-dialog-content p span {
background-image: url('path to image here')
no-repeat !important;
}
Am I doing something wrong? And if you have a complete primefaces documentation, that would also help. Thanks
You have 2 possibilities :
You can directly replace the icon overriding the Primefaces CSS like this :
CSS
.ui-icon.ui-confirm-dialog-severity {
background-position: 0 0 !important;
background-image: url('PATH TO IMAGE HERE') !important;
}
or you could do it like this : Inside the component which trigger the dialog :
XHTML
<p:confirm header="HEADER" message="MESSAGE" icon="ui-icon-alert" />
Example Here : http://www.primefaces.org/showcase/ui/confirmDialog.jsf
CSS
.ui-icon.ui-confirm-dialog-severity.ui-icon-alert {
background-position: 0 0 !important;
background-image: url('PATH TO IMAGE HERE') !important;
}

How to introduce HTML5 tag attributes and HTML5+CSS form validation for Struts2 tag elements

We are with extensive struts2 in our application. Now challenging task is to remove all struts2 default validation and introduce HTML5 with Css validation.
Example for struts2 form
<s:form id="userForm" action="userAction" method="post" validate="true">
<s:password key="Pwd" required="true" maxlength="128" />
</s:form>
in this i want to use HTML5 attribute "type=password" and "required" and pattern="(?=.\d)(?=.[a-zA-Z])\w{7,}" and want to make CSS validation for all these. How can i do this. Explanation with example or any related tutorial more appreciated.
I want this to explain the problem I am facing with css validation
Bellow is my struts form
<s:form id="userForm" action="userAction" method="post" validate="true">
<s:password key="Pwd" type="email" required="true" maxlength="128" id="password" pattern="(?=.*\d)(?=.*[a-zA-Z])\w{7,}"/>
<span class="form_hint">Password should contain,</br>
1.minimum of 7 characters. </br>
2. Must consist of only letters and digits.</br>
3.At least one letter and at least one digit</span>
</s:submit type="button">
</s:form>
I want to validate this password field for
1.required means user entered or not before submit,
2.password meets the given pattern criteria if yes i want to turn text to green color.
and my css is as bellow,
.form_hint {
background: #d45252;
border-radius: 3px 3px 3px 3px;
color: white;
margin-left:8px;
padding: 1px 6px;
z-index: 999;
position: absolute;
display: none;
}
.form_hint::before {
content: "\25C0";
color:#d45252;
position: absolute;
top:1px;
left:-6px;
}
#emailId input:focus + .form_hint {
display: inline;
}
#emailId input:required:valid + .form_hint {
background: #28921f;
}
#emailId input:required:valid + .form_hint::before {
color:#28921f;
}
But on screen when i click submit button with invalid password, just HTML5 pattern tag attribute is working with a message like "Please enter required format". how to make my css effective. what syntax I have to use in my CSS file. I mean "#emailId input:focus + .form_hint", "#emailId input:required:valid + .form_hint", "#emailId input:required:valid + .form_hint::before" are not taking effect in my form.
I have used jquery validation-engine with struts tag to apply css validations and have successfully implemented it.
This is the link of the tutorial I followed for jquery-validation engine:
http://www.skill-guru.com/blog/2010/04/18/jquery-validation-tutorial/
and this is how my struts tags look like :)
<s:textfield name="tenant.shortName" label="Short Name" labelSeparator=" " id="shortName" maxlength="3"
cssClass="validate[required,custom[noSpecialCaracters]] text-input"></s:textfield>
EDIT
OK so if you insist on using html5 this is your solution :
How do I specify HTML5 attributes with Struts 2.x? ...
and for using css you can use cssClass="" in struts tags for your css classes.
Note the span won't work inside <s:form> as <s:form> will flourish as tables when it is expanded by taglib. It is never adjacent to password in expanded html code..
One suggestion: You can use the title attribute to show things you want to on mouse hover.. or tooltip attribute in <s> tags
You are probably using the default XHTML Theme, that will generate additional HTML for you (the <fieldset> for example).
Then
switch to the Simple Theme, to gain full control over the generated HTML,
or, since your two fields are no more adjacent, use the ~ (General Sibling Combinator) instead of the + (Adjacent Sibling Combinator).

JSF commandLink with image

I have problem with <p:commandLink>. I want make hover effect but I can't load image to <p:graphicImage> via CSS.
CSS:
.accountEditBtn {
background-image:
url('#{request.contextPath}/resources/image/pencil_black.png');
}
JSF:
<p:commandLink
update="#form"
actionListener="#{someBean.someListener}">
<h:graphicImage styleClass="accountEditBtn" />
</p:commandLink>
I see empty rectangle with border.
But when I add alt to graphicImage, I get image over text from alt...
Where my mistake?
Thank you.
p.s. typing error - classType -> styleClass
try using styleClass instead of <h:graphicImage>
<p:commandLink
styleClass="accountEditBtn"
update="#form"
actionListener="#{someBean.someListener}"/>
try this class
.accountEditBtn { background-image: url('../resources/image/pencil_black.png'); }
B.T.W
isn't is should be images ? or it is image (folder name)
take a look at this as well.. in case you want commandButton with image: PrimeFaces icons
Why don't you use
<p:commandButton ... icon="yourbuttonstyleclass"/>
and in css
.yourbuttonstyleclass {
background-image: url('../images/yourimage.png') !important;
}

Resources