小编use*_*345的帖子

PRIMEFACES - 如何通过单击<p:commandButton>刷新<p:graphicImage>?

我正在考虑这个展示:http://www.primefaces.org/showcase/ui/dynamicImage.jsf,特别是子版"GraphicText on the the-fly".

我的问题是实现这个子案例的扩展版本,增加了一个.当按下按钮时,我需要图像改变.

在DynamicImageController类中,我重新编写了与graphicImage相关联的getter:

public StreamedContent getGraphicText(){
     double random = Math.random();// a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
     if(random>0.5){
         BufferedImage bufferedImg = new BufferedImage(100, 25, BufferedImage.TYPE_INT_RGB);  
         Graphics2D g2 = bufferedImg.createGraphics();  
         g2.drawString("This is a text", 0, 10);  
         ByteArrayOutputStream os = new ByteArrayOutputStream();  
         try {
            ImageIO.write(bufferedImg, "png", os);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
         graphicText = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png"); …
Run Code Online (Sandbox Code Playgroud)

ajax captcha primefaces page-refresh jsf-2

7
推荐指数
2
解决办法
9452
查看次数

将浏览器本地存储与 JSF2 和 Primefaces 结合使用

您好,这严格来说不是一个问题,我想分享我的解决方案,将浏览器本地存储与 JSF2 和 Primefaces 一起使用。

我发现有关使用本地存储与 jsf2 和 primefaces 的信息很少,因此分享我的工作似乎很有用。

支持豆:

@Component("pocLocalStorageBean")
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class PocLocalStorageBean {

    private static final long serialVersionUID = 1L;

    private String[] selectedCities;
    private List<String> cities;

    @PostConstruct
    public void initialize() {
            List<String> cities = new ArrayList<String>();
            cities.add("Miami");
            cities.add("London");
            cities.add("Paris");
            cities.add("Istanbul");
            cities.add("Berlin");
            cities.add("Barcelona");
            cities.add("Rome");
            cities.add("Brasilia");
            cities.add("Amsterdam");

            setCities(cities);

    }

    //GETTER E SETTER HERE    
}
Run Code Online (Sandbox Code Playgroud)

页面xhtml:

 <h:form id="yuorFormId" cache="false">

     <p:remoteCommand name="updateUiAfterLoadChoicesFromLocalStorage" update=":yuorFormId:yourSelectManyCheckboxId">
     </p:remoteCommand>
    <p:remoteCommand oncomplete="loadCitiesChoicesFromLocalStorage(#{pocLocalStorageBean.cities.size()});" autoRun="true">
     </p:remoteCommand>

    <div class="ui-g ui-fluid">

      <div class="ui-g-12 ui-md-12">

            <div class="card">

                    <p:selectManyCheckbox id="yourSelectManyCheckboxId" value="#{pocLocalStorageBean.selectedCities}" layout="responsive" …
Run Code Online (Sandbox Code Playgroud)

primefaces jsf-2

6
推荐指数
0
解决办法
1703
查看次数

标签 统计

jsf-2 ×2

primefaces ×2

ajax ×1

captcha ×1

page-refresh ×1