2013-08-27 3 views
0

데이터 테이블의 데이터 색상을 변경하고 싶습니다.primefaces 데이터 테이블의 텍스트 부분에 스타일 지정하기

예 : 에는 두 개의 값 (64 및 64)이 있습니다.

은 : 64

64 

B는 두 개의 값 60, 65

는 B있다 : 60

65 



<p:dataTable var="someclass" value="#{someBean.someclass}"> 
<p:column headerText="DEVICE" > 
<h:outputText value="#{someclass.somemember}" /> 
</p:column> 
<p:column headerText="PATH"> 
<h:outputText value="#{someclass.somemember}" />        
</p:column> 
</p:dataTable> 

'는'은 그것이 하나에 표시되어야 두 개의 동일한 값이 있으면 값이 다른 경우 다른 색상이 나는 다른 색상의 데이터가 필요합니다.

primefaces datatable을 어떻게 사용할 수 있습니까?

우리가 이것을 수행 할 수있는 primefaces (데이터 테이블없이)를 사용하는 다른 방법이 있습니까?

그의 내가 내 표현처럼하는 방법입니다 ....... {#의 some.path EQ를 "설치 경로"} & & some.path + 1 EQ "경로가 사용 된 경우

)} 다음 {경우 (# (some.path.substringAfter (':') EQ (# (some.path + 1.substringAfter (':'?)이 사용 JSF를 제공하는 방법을

...

+0

보여 추가를하여 관련 'p : datatable'c ode,'p : column' 내용 – Daniel

+0

나는 내용을 편집했습니다. 그것을 확인해주세요. – Pramoth

+0

* DEVICE * memeber가 * PATH * member와 같으면 어떻게됩니까? – Daniel

답변

0

여기에 가장 필요한 것은 무엇이든지, 적어도 일반 아이디어를 얻을 수 있습니다.

귀하의 XHTML은 다음과 같아야합니다

public <T> T peek(ListIterator<T> iter) throws NoSuchElementException { 
    T obj = iter.next(); 
    iter.previous(); 
    return obj; 
} 

경우 MyObject : peek 방법은 다음과 같습니다 어디

<p:dataTable var="myLittleWrapper" value="#{myBean.modified}"> 
    <p:column headerText="PATH"> 
     <h:outputText value="#{myLittleWrapper.myObject.path}" styleClass="#{(myLittleWrapper.colorMe)?'equalMembers':''}"/>        
    </p:column> 
... 

는 다음과 같은 방법을 (당신에게서 @PostConstruct를 호출)

List<MyObject> original = new ArrayList<MyObject>();//fill it with data 
List<MyObjectWrapper> modified = new ArrayList<MyObjectWrapper>();// + getter/setter 

public void prepareModifiedList() { 

    ListIterator<MyObject> myListIter = original.listIterator(); 

    while (myListIter.hasNext()) { 
     MyObject myObj = myListIter.next(); 
     MyObject nextMyObj = null; 
     boolean colorMe = false; 
     try { 
      nextMyObj = peek(myListIter); 
     } catch (NoSuchElementException e) { 
     } 
     if (nextMyObj != null && myObj.getPath().equals(nextMyObj.getPath())) { 
      colorMe = true; 
     } 
     MyObjectWrapper myObjectWrapper = new MyObjectWrapper(myObj, colorMe); 
     modified.add(myObjectWrapper); 

    } 
} 

만들기 MyObjectWrapper은 다음과 같습니다.

public class MyObject { 

    public MyObject(String path) { 
     super(); 
     this.path = path; 
    } 

    private String path; 

    public String getPath() { 
     return path; 
    } 

    public void setPath(String path) { 
     this.path = path; 
    } 
} 

그리고

public class MyObjectWrapper { 
    MyObject myObject; 

    boolean colorMe; 

    public MyObjectWrapper(MyObject myObject, boolean colorMe) { 
     super(); 
     this.myObject = myObject; 
     this.colorMe = colorMe; 
    } 

    public MyObject getMyObject() { 
     return myObject; 
    } 

    public void setMyObject(MyObject myObject) { 
     this.myObject = myObject; 
    } 

    public boolean isColorMe() { 
     return colorMe; 
    } 

    public void setColorMe(boolean colorMe) { 
     this.colorMe = colorMe; 
    } 

} 

난 당신이 뭔가 할 수있는 권리를 이해하는 경우 :

<h:outputText value="#{someclass.somemember}" 
    styleClass="#{(someclass.someMember eq someclass.someOtherMember)?'equalMembers':''}"/> 

당신의 CSS에서

.equalMembers { 
    color:red; 
} 
+0

고마워요 댄. 나는 거의 그것을 얻었다. 경로 : 12 23 34 45. 다음 행에는 다음 값이 있습니다. 12 23 34 56 .. 다음 3 n 4 행에는 다른 데이터가있는 경로가 있습니다. 내가 얻을 데이터는 전체 문장입니다. 나는 "경로 : 12 23 34 45"를 의미합니다. 그래서 콜론 (:) 다음에 데이터를 가져 와서 비교할 필요가 있습니다. – Pramoth

관련 문제